package spider

import (
	"fmt"
	"math"
	"time"

	"priceApi/models"
	"priceApi/utils"

	"github.com/astaxie/beego/orm"
)

func Round(f float64, n int) float64 {
	pow10_n := math.Pow10(n)
	return math.Trunc((f+0.5/pow10_n)*pow10_n) / pow10_n
}

func SaveRate(rate float64) {
	fmt.Println(rate)
	rate = Round(rate, 2)
	fmt.Println(rate)

	if rate > 0 {
		o := orm.NewOrm()
		rate0 := new(models.Rate)
		rate0.Rate = rate
		rate0.Created = int(time.Now().Unix())
		o.Insert(rate0)
	} else {
		utils.SendToMail("SaveRate", "数值小于等于零")
	}

}

func GetHuobiUSDT() {

	//获取USDT汇率
	//rate := GetHuobiUsdtPrice("sell")
	//fmt.Println(rate1)
	//获取阿里USD汇率
	//rate := GetAliyunRate()

	//SaveRate(rate)
}
